package pers.zc.activiti.websocket.controller;

import com.jcraft.jsch.JSchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import pers.zc.activiti.websocket.service.WebSocketServer;

import java.io.IOException;

/**
 * @description websocket
 * @Author Lin FuYuan
 * @date 2020/5/6
 */
@RestController
@RequestMapping("/websocket")
@ResponseBody
public class WebSocketController  {

    @Autowired
    private WebSocketServer webSocketServer;

    @GetMapping("onOpen")
    public void onOpen(@RequestParam String userId){
    }
    @GetMapping("onClose")
    public void onClose(){
        webSocketServer.onClose();
    }


    @GetMapping("index")
    public ResponseEntity<String> index(){
        return ResponseEntity.ok("请求成功");
    }

    @GetMapping("page")
    public ModelAndView page(){
        return new ModelAndView("websocket");
    }

    @GetMapping("/push")
    public ResponseEntity<String> pushToWeb( String message, @RequestParam String id) throws IOException, JSchException {
        WebSocketServer.sendInfo(message,id);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

}
